#include <iostream>
using namespace std;

//https://leetcode.cn/problems/reverse-only-letters/
class Solution
{
public:

    bool isletter(char& ch)
    {
        return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
    }

    string reverseOnlyLetters(string s)
    {
        int n = s.size();
        int left = 0, right = n - 1;
        while (left < right)
        {
            while (left < right && !isletter(s[left]))
            {
                left++;
            }

            while (left < right && !isletter(s[right]))
            {
                right--;
            }

            swap(s[left++], s[right--]);
        }
        return s;
    }
};

void test01()
{
    //string s("ab - cd");
    string s2("7_28]");
    Solution solu;
    auto result = solu.reverseOnlyLetters(s2);
    cout << "result:" << result << endl;
}



int main()
{
    test01();
    //test02();
    return 0;
}